package com.ruoyi.voucher.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.voucher.service.IVoucherAttachmentService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.voucher.domain.VoucherAttachment;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 凭证附件Controller
 *
 * @author ruoyi
 * @date 2025-02-25
 */
@RestController
@RequestMapping("/finance_voucher/attachment")
public class VoucherAttachmentController extends BaseController
{
    @Autowired
    private IVoucherAttachmentService voucherAttachmentService;

    /**
     * 查询凭证附件列表
     */
    @PreAuthorize("@ss.hasPermi('finance_voucher:attachment:list')")
    @GetMapping("/list")
    public TableDataInfo list(VoucherAttachment voucherAttachment)
    {
        startPage();
        List<VoucherAttachment> list = voucherAttachmentService.selectVoucherAttachmentList(voucherAttachment);
        return getDataTable(list);
    }

    /**
     * 导出凭证附件列表
     */
    @PreAuthorize("@ss.hasPermi('finance_voucher:attachment:export')")
    @Log(title = "凭证附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VoucherAttachment voucherAttachment)
    {
        List<VoucherAttachment> list = voucherAttachmentService.selectVoucherAttachmentList(voucherAttachment);
        ExcelUtil<VoucherAttachment> util = new ExcelUtil<VoucherAttachment>(VoucherAttachment.class);
        util.exportExcel(response, list, "凭证附件数据");
    }

    /**
     * 获取凭证附件详细信息
     */
    @PreAuthorize("@ss.hasPermi('finance_voucher:attachment:query')")
    @GetMapping(value = "/{attachmentId}")
    public AjaxResult getInfo(@PathVariable("attachmentId") Long attachmentId)
    {
        return success(voucherAttachmentService.selectVoucherAttachmentByAttachmentId(attachmentId));
    }

    /**
     * 新增凭证附件
     */
    @PreAuthorize("@ss.hasPermi('finance_voucher:attachment:add')")
    @Log(title = "凭证附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VoucherAttachment voucherAttachment)
    {
        return toAjax(voucherAttachmentService.insertVoucherAttachment(voucherAttachment));
    }

    /**
     * 修改凭证附件
     */
    @PreAuthorize("@ss.hasPermi('finance_voucher:attachment:edit')")
    @Log(title = "凭证附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VoucherAttachment voucherAttachment)
    {
        return toAjax(voucherAttachmentService.updateVoucherAttachment(voucherAttachment));
    }

    /**
     * 删除凭证附件
     */
    @PreAuthorize("@ss.hasPermi('finance_voucher:attachment:remove')")
    @Log(title = "凭证附件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{attachmentIds}")
    public AjaxResult remove(@PathVariable Long[] attachmentIds)
    {
        return toAjax(voucherAttachmentService.deleteVoucherAttachmentByAttachmentIds(attachmentIds));
    }
}
